package com.se2.antiqueexhibition.Service.impl;

import com.se2.antiqueexhibition.Mapper.RelicCategoryMapper;
import com.se2.antiqueexhibition.Service.RelicCategoryService;
import com.se2.antiqueexhibition.pojo.RelicCategory;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RelicCategoryServiceimpl implements RelicCategoryService {

    @Resource
    private RelicCategoryMapper relicCategoryMapper;

    @Override
    public List<RelicCategory> getAllCategories() {
        return relicCategoryMapper.selectAll();
    }

    @Override
    public RelicCategory getCategoryById(int id) {
        return relicCategoryMapper.selectById(id);
    }

    @Override
    @Transactional
    public void addCategory(RelicCategory relicCategory) {
        relicCategoryMapper.insert(relicCategory);
    }

    @Override
    @Transactional
    public void updateCategory(RelicCategory relicCategory) {
        relicCategoryMapper.update(relicCategory);
    }

    @Override
    @Transactional
    public void deleteCategory(int id) {
        relicCategoryMapper.delete(id);
    }

    @Override
    public boolean isNameExists(String name) {
        return relicCategoryMapper.countByName(name) > 0;
    }
}

